package com.mingyizhudao.app.view.mine;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.dixiang.framework.common.QjResult;
import com.dixiang.framework.widget.LoadingDialog;
import com.google.gson.reflect.TypeToken;
import com.mingyizhudao.app.R;
import com.mingyizhudao.app.utils.CommonUtils;
import com.mingyizhudao.app.utils.Constants;
import com.mingyizhudao.app.utils.IntentHelper;
import com.mingyizhudao.app.view.MYBaseActivity;
import com.mingyizhudao.app.view.mine.bean.CommentEntity;
import com.mingyizhudao.app.view.mine.bean.OrderItemEntity;

public class CommentWatchActivity extends MYBaseActivity{

	private OrderItemEntity orderItemEntity;

	private TextView tv_doctor_name,order_no,tv_yuyue,tv_fuwufei,tv_comment,tv_go_details;

	private RatingBar rb_1,rb_2;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_comment_watch);
		activity = this;
		initView();
		getOrderDetail();
	}
	
	@Override
	public void initHeaderView() {
		setTitleViewValue("我的评价");
		setTitleViewValue(0,0,R.color.white);
		setTopViewBg(R.color.actionbar_bg_color);
		initBackView(R.drawable.left_back_white_icon, 0, new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	private void initView(){
		orderItemEntity = (OrderItemEntity) getIntent().getSerializableExtra("orderItemEntity");
		tv_doctor_name = (TextView) findViewById(R.id.tv_doctor_name);
		order_no = (TextView) findViewById(R.id.order_no);
		tv_yuyue = (TextView) findViewById(R.id.tv_yuyue);
		tv_fuwufei = (TextView) findViewById(R.id.tv_fuwufei);
		rb_1 = (RatingBar) findViewById(R.id.rb_1);
		rb_2 = (RatingBar) findViewById(R.id.rb_2);
		tv_comment = (TextView) findViewById(R.id.tv_comment);
		tv_go_details = (TextView) findViewById(R.id.tv_go_details);

		tv_go_details.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
             
				 IntentHelper.getInstance(activity).gotoActivityWithURL(OrderDetailActivity.class, getIntent().getStringExtra(Constants.PARM_ACTION_URL));

			}
		});
	}
	
	
	private void getOrderDetail(){

		LoadingDialog.getInstance(activity).show();
		String url = getIntent().getStringExtra(Constants.PARM_ACTION_URL)+CommonUtils.getTokenParam(activity);;

		getHttpResult(url, Constants.HTTP_INDEX.First, new TypeToken<QjResult<OrderItemEntity>>() {});
	}

	@Override
	public void onSuccess(QjResult result, String flg) {
		super.onSuccess(result, flg);

		if(flg.equals(Constants.HTTP_INDEX.First)){
			orderItemEntity = (OrderItemEntity)result.getResults();

			if(orderItemEntity != null){
				//				id = orderItemEntity.getId();
				//				setOrderDetail();

				String name = orderItemEntity.getExpertName();
				if (name!=null&&name.length()>0&&!"null".equals(name)&&!"".equals("未填写")) {
					tv_doctor_name.setText("："+name);
				}
				order_no.setText(orderItemEntity.getRefNo());
				tv_yuyue.setText(orderItemEntity.getDepositTotalAmount()+"元");
				tv_fuwufei.setText(""+orderItemEntity.getServiceTotalAmount()+"元");

				CommentEntity  comment =orderItemEntity.getComment();
				if (comment!=null) {
					rb_1.setRating( Integer.parseInt(comment.getDoctor_attitude()));
					rb_2.setRating( Integer.parseInt(comment.getEffect()));
					tv_comment.setText(comment.getComment_text());
				}
				

			}else{
				Toast.makeText( activity, "获取数据失败！", 0 ).show();	
			}

		}

	}

	@Override
	public void onCompleted(Exception e, String flg) {
		super.onCompleted(e, flg);
		LoadingDialog.getInstance(activity).dismiss();
	}


}
